package com.xqb.modules.controller.course;

import com.xqb.common.annotation.Anonymous;
import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.LesCourseTeacher;
import com.xqb.modules.domain.vo.CourseInsTeacherVo;
import com.xqb.modules.service.ILesCourseTeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课程老师关系Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/course/teacher")
public class LesCourseTeacherController extends BaseController
{
    @Autowired
    private ILesCourseTeacherService lesCourseTeacherService;

    /**
     * 查询课程老师关系列表
     */
    @PreAuthorize("@ss.hasPermi('course:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(LesCourseTeacher lesCourseTeacher)
    {
        startPage();
        List<LesCourseTeacher> list = lesCourseTeacherService.selectLesCourseTeacherList(lesCourseTeacher);
        return getDataTable(list);
    }

    /**
     * 导出课程老师关系列表
     */
    @PreAuthorize("@ss.hasPermi('course:teacher:export')")
    @Log(title = "课程老师关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LesCourseTeacher lesCourseTeacher)
    {
        List<LesCourseTeacher> list = lesCourseTeacherService.selectLesCourseTeacherList(lesCourseTeacher);
        ExcelUtil<LesCourseTeacher> util = new ExcelUtil<LesCourseTeacher>(LesCourseTeacher.class);
        util.exportExcel(response, list, "课程老师关系数据");
    }

    /**
     * 获取课程老师关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:teacher:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(lesCourseTeacherService.selectLesCourseTeacherById(id));
    }

    /**
     * 新增课程老师关系
     */
    @PreAuthorize("@ss.hasPermi('course:teacher:add')")
    @Log(title = "课程老师关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LesCourseTeacher lesCourseTeacher)
    {
        return toAjax(lesCourseTeacherService.insertLesCourseTeacher(lesCourseTeacher));
    }

    /**
     * 修改课程老师关系
     */
    @PreAuthorize("@ss.hasPermi('course:teacher:edit')")
    @Log(title = "课程老师关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LesCourseTeacher lesCourseTeacher)
    {
        return toAjax(lesCourseTeacherService.updateLesCourseTeacher(lesCourseTeacher));
    }

    /**
     * 删除课程老师关系
     */
    @PreAuthorize("@ss.hasPermi('course:teacher:remove')")
    @Log(title = "课程老师关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(lesCourseTeacherService.deleteLesCourseTeacherByIds(ids));
    }

    /**
     * 用户端获取课程的老师
     */
    @ApiOperation(value = "用户端获取课程的老师")
    @GetMapping("/getCourseInsTeacher/{courseId}")
    @Anonymous
    public AjaxResult getCourseInsTeachers(@PathVariable Long courseId) {
        CourseInsTeacherVo list = lesCourseTeacherService.getCourseTeacherAndIns(courseId);
        return success(list);
    }
}
